<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="dao.QueryPlaces"%>
<%@page import="dao.Entity.Places"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.Entity.Place"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="./script/jquery.js" type="text/javascript"></script>
        <link href="css/allcss.css" rel="stylesheet" type="text/css"/>
        <link rel="shortcut icon"  href="image/icon6.ico" type="image/x-icon" /> 
        <title>Places</title>
        <style>
            #op4{
                color:#00aeec;
            }
        </style>
    </head>
    <body>
        <div id="aside">
            <img id="icon" src="./image/icon6.png">
            <div id="p1">管理员界面</div>    
        </div>
        <div id="main">
            <div id="list"><div id="op1" class="options">全部预约</div><div  id="op2" class="options">未审核</div>
                <div  id="op3" class="options">已审核</div><div  id="op4" class="options">地点管理</div>
                <div  id="op5" class="options">地点上新</div><div  id="op6" class="options">数据库管理</div>
                <div  id="op7" class="options">学生信用度</div><div  id="op8" class="options">申诉回复</div>
            </div>
            <div id="content">
                <%
                    ArrayList<Place> res = QueryPlaces.getResult().places;
                    for (int i = 0; i < res.size(); i++) {
                        String st = res.get(i).getStatus() == 1 ? "开放" : "维护";
                        String placeNumber = res.get(i).PlaceNumber;
                        String button = "<button  id='places_change_button_number" + i + "'  class='places_change_button'  onclick='add(event)' value='" + placeNumber + "' >更新时间段</button>";
                        String color = res.get(i).getStatus() == 1 ? "green" : "red";
                        out.println("<div  class='places' id='place" + placeNumber + "'><div class='place' >地点号：[" + placeNumber
                                + "] 地点名称：[" + res.get(i).PlacePosition + "] </div><div id='status" + placeNumber + "' class='place_status' style='color:" + color + ";'>状态:[" + st + "]</div><img class='place_img' src='./placeImage/" + res.get(i).PlaceImage + "'/>"
                                + button
                                + "<button class='places_open_button' name='" + placeNumber + "'>启用</button><button class='places_stop_button' name='" + placeNumber + "'>维护</button>"
                                + "<button class='places_update_button' name='" + placeNumber + "'>修改信息</button><button class='places_del_button' name='" + placeNumber + "'>删除</button></div>");
                    }
                %>
            </div>
        </div> 
        <script src="./script/button.js" type="text/javascript"></script>
        <script>
            $(".places_open_button").click(function () {
                var name = $(this).attr('name');
                $.get("./Servlet/changePlaceStatusServlet?opType=1&placeNumber=" + name, function (data, status) {
                    if (status) {
                        if (data !== "1") {
                            alert("失败");
                        } else {
                            alert("成功");
                            $("#status" + name).html("状态:[开放]");
                            $("#status" + name).css("color", "green");
                        }
                    }
                }
                );
            });
            $(".places_stop_button").click(function () {
                var name = $(this).attr('name');
                $.get("./Servlet/changePlaceStatusServlet?opType=0&placeNumber=" + name, function (data, status) {
                    if (status) {
                        if (data !== "1") {
                            alert("失败");
                        } else {
                            alert("成功");
                            $("#status" + name).html("状态:[维护]");
                            $("#status" + name).css("color", "red");
                        }
                    }
                }
                );
            });
            $(".places_del_button").click(function () {
                if (confirm("确定要删除吗？")) {
                    var name = $(this).attr('name');
                    $.get("./Servlet/changePlaceStatusServlet?opType=2&placeNumber=" + name, function (data, status) {
                        if (status) {
                            if (data !== "1") {
                                alert("失败");
                            } else {
                                alert("成功");
                                $("#place" + name).remove();
                            }
                        }
                    }
                    );
                }
            });
            $(".places_update_button").click(function (event) {
                window.location.href = "updatePlaceinf.html?placeNumber=" + event.target.name;
            });
            function add(event) {
                var id = event.target.id;
                var placeNumber = event.target.value;
                window.location.href = "updatePlace.jsp?placenumber=" + placeNumber;
            }
        </script>
    </body>
</html>

